package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.UserRelationPushCid;
import com.sc.nft.mapper.UserRelationPushCidMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * @author 刘国航
 * @desc
 * @since 2024/6/14 11:25
 */
@Slf4j
@Repository
public class UserRelationPushCidDao extends ServiceImpl<UserRelationPushCidMapper, UserRelationPushCid> {

    public UserRelationPushCid getByUserId(Long userId) {
        LambdaQueryWrapper<UserRelationPushCid> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRelationPushCid::getUserId, userId);
        queryWrapper.orderByDesc(UserRelationPushCid::getBindTime);
        queryWrapper.last("limit 1");
        return baseMapper.selectOne(queryWrapper);
    }

    public List<UserRelationPushCid> getListByUserId(Long userId) {
        LambdaQueryWrapper<UserRelationPushCid> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRelationPushCid::getUserId, userId);
        queryWrapper.orderByDesc(UserRelationPushCid::getBindTime);
        return baseMapper.selectList(queryWrapper);
    }

    public List<UserRelationPushCid> getByCid(String cid) {
        LambdaQueryWrapper<UserRelationPushCid> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRelationPushCid::getCid, cid);
        return baseMapper.selectList(queryWrapper);
    }

    public Page<UserRelationPushCid> getPageByUserIdList(Page<UserRelationPushCid> page, List<Long> userIdList) {
        LambdaQueryWrapper<UserRelationPushCid> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(UserRelationPushCid::getUserId, userIdList);
        queryWrapper.orderByDesc(UserRelationPushCid::getId);
        return baseMapper.selectPage(page,queryWrapper);
    }

}
